package main;

import cn.hutool.core.util.URLUtil;
import cn.hutool.json.JSONObject;

import java.util.ArrayList;
import java.util.Comparator;

import static main.Judge.onlineDeviceList;

/**
 * @author hanj.cn@outlook.com
 */
public class TimerTask extends java.util.TimerTask {

    @Override
    public void run() {

        try {

            ArrayList<JSONObject> devices = MyUtils.getDevices();

            assert devices != null;
            for (JSONObject device : devices) {

                String deviceName = URLUtil.decode(device.get("hostname", String.class));

                if (!onlineDeviceList.contains(deviceName)) {

                    onlineDeviceList.add(deviceName);
                }

            }

            // 排序
            onlineDeviceList.sort(Comparator.reverseOrder());
        } catch (Exception e) {

            e.printStackTrace();
        }
    }

}
